package com.tiancheng.trade.merchant.enums;

import lombok.AllArgsConstructor;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 收入确认规则枚举
 *
 * @author Likailun
 * @date 11:10 2021/4/23
 */
@AllArgsConstructor
public enum RevenueTypeEnum {
    ALL("ALL", "全额确认", "销售金额=收入", false),
    PART("PART", "差额确认", "销售金额-成本金额=收入", false),
    FIXED_SCALE("FIXED_SCALE", "固定比例", "销售金额*固定比例=收入", true),
    FIXED_AMOUNT("FIXED_AMOUNT", "固定金额", "销售数量*固定金额=收入", true),
    ;

    /**
     * 收入确认类型
     */
    private String revenueType;

    /**
     * 收入确认类型-名称
     */
    private String revenueTypeName;

    /**
     * 收入确认类型-描述
     */
    private String revenueTypeDesc;

    /**
     * 收入确认类型-是否自定义
     */
    private Boolean custom;

    public String getRevenueType() {
        return revenueType;
    }

    public void setRevenueType(String revenueType) {
        this.revenueType = revenueType;
    }

    public String getRevenueTypeName() {
        return revenueTypeName;
    }

    public void setRevenueTypeName(String revenueTypeName) {
        this.revenueTypeName = revenueTypeName;
    }

    public String getRevenueTypeDesc() {
        return revenueTypeDesc;
    }

    public void setRevenueTypeDesc(String revenueTypeDesc) {
        this.revenueTypeDesc = revenueTypeDesc;
    }

    public Boolean getCustom() {
        return custom;
    }

    public void setCustom(Boolean custom) {
        this.custom = custom;
    }

    public static List<RevenueTypeEnum> getAll() {
        return Arrays.stream(RevenueTypeEnum.values()).collect(Collectors.toList());
    }

    public static String getRevenueTypeNameByCode(String code) {
        return Arrays.stream(values()).filter(c -> c.revenueType.equals(code)).findFirst()
                .map(RevenueTypeEnum::getRevenueTypeName).orElse("");
    }

    /**
     * 根据revenueType获取具体枚举，一般switch中使用
     *
     * @param revenueType
     * @return
     */
    public static RevenueTypeEnum getByRevenueType(String revenueType) {
        return Arrays.stream(values()).filter(d -> Objects.equals(d.getRevenueType(), revenueType)).findFirst().orElse(null);
    }
}
